$(function() {
	var clickleve;
	var clicktype;
	var approval_leve1 = 1;
	var approval_leve2 = 1;
	var tab1Scroll = new IScroll('#tab1', {
		mouseWheel: true,
		disableMouse: true,
		disablePointer: true,
		scrollbars: 'custom',
		interactiveScrollbars: true,
	});
	var tab2Scroll = new IScroll('#tab2', {
		mouseWheel: true,
		disableMouse: true,
		disablePointer: true,
		scrollbars: 'custom',
		interactiveScrollbars: true,
	});
	$.ajax({
			type: "post",
			url: "{:url('/unit/index/getInfo')}",
			data: {},
			success: function(res) {
				if(res.data.prop==4){
				for(var i=0;i<$('.finance').length;i++){
					if($('.finance').length>1){
					$('.finance').eq(i).remove()
					i--
					}else{
						$('.finance').eq(0).remove()
					}
					
				}
				$('.tab-ul .unit').eq(0).addClass('am-active')
				$('.#tab2').addClass('am-in ')
				$('.#tab2').addClass('am-active')
			}
			}
	})
	$('.isapproval-process').on('click', function() {
		console.log(1);
		if($(this).find('input').prop('checked')) {
			$('.approval-process').css('display', 'block');
		} else {
			$('.approval-process').css('display', 'none');
		}

	});
	$('.add_approve_leve').on('click', function() {
		if($(this).data('tab') == 1) {
			approval_leve1++;
			addapprovel(1, approval_leve1);
			$('.add_approve_people').unbind()
			$('.add_approve_people').on('click', function() {
				clickleve = $(this).data('leve')
				clicktype = $(this).data('type')
				addapproveprople(clickleve, clicktype)
			});
		} else {
			approval_leve2++;
			addapprovel(2, approval_leve2);
			$('.add_approve_people').unbind()
			$('.add_approve_people').on('click', function() {
				console.log(122)
				clickleve = $(this).data('leve')
				clicktype = $(this).data('type')
				addapproveprople(clickleve, clicktype)
			});
		}
	});
	$('.back').on('click', function() {
		window.history.go(-1);
	})

	$('.add_approve_people').on('click', function() {
		clickleve = $(this).data('leve')
		clicktype = $(this).data('type')
		addapproveprople(clickleve, clicktype)
	});
	{if $Think.get.limit_id}
		$.ajax({
			type: "post",
			url: "{:url('/unit/limit/all')}",
			success: function(res) {
				$("#loading-first").fadeOut(500);
				for(var i=0;i<res.data.length;i++){
				if(res.data[i].state==1){
					res.data[i].state_main='启用中'
				}else{
					res.data[i].state_main='禁用中'
				}
				res.data[i].limit_rule=JSON.parse(res.data[i].limit_rule)
				if(res.data[i].limit_type==2){
					res.data[i].limittype='财政'
					if(res.data[i].limit_rule.need_check){
						res.data[i].need_check='需审批'
					}else{
						res.data[i].need_check='不需审批'
					}
				}else{
					res.data[i].limittype='单位'
					res.data[i].need_check='需审批'
				}
			}
				var limit_detail;
				for(var didx=0;didx<res.data.length;didx++){
					if(res.data[didx].limit_id=={$Think.get.limit_id?:""}){
						limit_detail=res.data[didx]
					}
				}
				console.log(limit_detail)
				if(limit_detail.limit_type==1){
					$("select[name='limit_rule[type][]']").eq(1).selected({
					   btnWidth:'200px', btnSize: 'sm'
					});
					
					$("select[name='limit_rule[car_type][]']").eq(1).selected({
					   btnWidth:'200px', btnSize: 'sm'
					});
					getvalue(1,limit_detail)
					
				}else{
					$("select[name='limit_rule[car_type][]']").eq(0).selected({
					   btnWidth:'200px', btnSize: 'sm'
					});
					$("select[name='limit_rule[type][]']").eq(0).selected({
					   btnWidth:'200px', btnSize: 'sm'
					});
					
					getvalue(2,limit_detail)
				}
				
				
				
				
				
			}
		})
		function getvalue(typenum,limit_detail){
			console.log(limit_detail)
			if(typenum==2){
				$('.tab-ul .finance').removeClass('am-active')
				$('.tab-ul .unit').addClass('am-active')
				$('#tab2').addClass('am-active');
				$('#tab2').addClass('am-in');
				$('#tab1').removeClass('am-active');
				$('#tab1').removeClass('am-in');
				if(limit_detail.limit_rule.need_check){
					$('input[name="limit_rule[need_check]"]').attr('checked','check')
					console.log()
					$('#tab2 .approval-process').css('display','block')
				}
			}else{
				$('.tab-ul .unit').removeClass('am-active')
				$('.tab-ul .finance').eq(0).addClass('am-active')
				$('#tab1').addClass('am-active');
				$('#tab1').addClass('am-in');
				$('#tab2').removeClass('am-active');
				$('#tab2').removeClass('am-in');
			}
			if(limit_detail){
				$('#tab'+typenum).find('input[name="limit_name"]').eq(0).val(limit_detail.limit_name);
					if(limit_detail.limit_rule){
					if(limit_detail.limit_rule.date){
						$('#tab'+typenum).find('.use_car_date').find('.use_car_ra').eq(0).uCheck('uncheck')
						$('#tab'+typenum).find('.use_car_date').find('.use_car_ra').eq(1).uCheck('check')
						$('#tab'+typenum).find('input[name="limit_rule[date][start]"]').eq(0).prop('readonly', false);
						$('#tab'+typenum).find('input[name="limit_rule[date][end]"]').eq(0).prop('readonly', false);
						$('#tab'+typenum).find('input[name="limit_rule[date][start]"]').eq(0).val(limit_detail.limit_rule.date.start);
						$('#tab'+typenum).find('input[name="limit_rule[date][end]"]').eq(0).val(limit_detail.limit_rule.date.end);
					}
					$('#tab'+typenum).find('input[name="limit_rule[address]"]').eq(0).val(limit_detail.limit_rule.address);
					if(limit_detail.limit_rule.type){
						var selecttype=$('#tab'+typenum).find('select[name="limit_rule[type][]"]').find('option')
						for(var typeidx=0;typeidx<selecttype.length;typeidx++){
							for(var typeidx2=0;typeidx2<limit_detail.limit_rule.type.length;typeidx2++){
								if(limit_detail.limit_rule.type[typeidx2]==selecttype.eq(typeidx).val()){
									selecttype.eq(typeidx).attr('selected', true);
									
								}
							}
						}
						selecttype.parent().selected({
						   btnWidth:'200px', btnSize: 'sm'
						  });
					}else{
						var selecttype=$('#tab'+typenum).find('select[name="limit_rule[type][]"]').find('option')
						selecttype.parent().selected({
						   btnWidth:'200px', btnSize: 'sm'
						  });
					}
					if(limit_detail.limit_rule.car_type){
					$('#tab'+typenum).find('select[name="limit_rule[car_type][]"]').eq(0).val();
						var selecttype1=$('#tab'+typenum).find('select[name="limit_rule[car_type][]"]').find('option')
						var car_type;
						for(var typeidx=0;typeidx<selecttype1.length;typeidx++){
							for(var typeidx2=0;typeidx2<limit_detail.limit_rule.car_type.length;typeidx2++){
								if(limit_detail.limit_rule.car_type[typeidx2]==selecttype1.eq(typeidx).val()){
									console.log(selecttype1.eq(typeidx))
									selecttype1.eq(typeidx).attr('selected', true);
//									
								}
							}
						}
						selecttype1.parent().selected({
						   btnWidth:'200px', btnSize: 'sm'
						  });
					}else{
						var selecttype1=$('#tab'+typenum).find('select[name="limit_rule[car_type][]"]').find('option')
						selecttype1.parent().selected({
						   btnWidth:'200px', btnSize: 'sm'
						  });
					}
					//每日限额
					if(limit_detail.limit_rule.quota_day){
						$('#tab'+typenum).find('.limit-w').find('.limit').eq(0).uCheck('uncheck')
						$('#tab'+typenum).find('.limit-w').find('.limit').eq(1).uCheck('check')
						$('#tab'+typenum).find('input[name="limit_rule[quota_day]"]').eq(0).prop('readonly', false);
						$('#tab'+typenum).find('input[name="limit_rule[quota_day]"]').eq(0).val(limit_detail.limit_rule.quota_day);
					}
					//审批员
					if(limit_detail.limit_rule.checker){
						var count=0;
						for(var i in limit_detail.limit_rule.checker){
					        count ++;
					    }
						if(typenum==1){
						addapproveshow2(1, 1,limit_detail.limit_rule.checker[1])
						}else{
						addapproveshow2(1, 2,limit_detail.limit_rule.checker[1])	
						}
						if(count==2){
							if(typenum==1){
							addapprovel(1, 2)
							addapproveshow2(2, 1,limit_detail.limit_rule.checker[2])
							}else{
							addapprovel(2, 2)
							addapproveshow2(2, 2,limit_detail.limit_rule.checker[2])	
							}
						}else if(count==3){
							if(typenum==1){
								addapprovel(1, 2)
								addapproveshow2(2, 1,limit_detail.limit_rule.checker[2])
								addapprovel(1, 3)
								addapproveshow2(3, 1,limit_detail.limit_rule.checker[3])
							}else{
								addapprovel(2, 2)
								addapproveshow2(2, 2,limit_detail.limit_rule.checker[2])
								addapprovel(2, 3)
								addapproveshow2(3, 2,limit_detail.limit_rule.checker[3])
							}
						}
					}
					//用车时间
					if(limit_detail.limit_rule.time){
						var timemain='';
						if(limit_detail.limit_rule.time.work){
							if(limit_detail.limit_rule.time.work.start==''){}else{
								timemain += `<div>
											<div>工作日 ${limit_detail.limit_rule.time.work.start}-${limit_detail.limit_rule.time.work.end}</div>
										</div>`;
							}
						$('#tab'+typenum).find('input[name="limit_rule[time][work][start]"]').eq(0).val(limit_detail.limit_rule.time.work.start);
						$('#tab'+typenum).find('input[name="limit_rule[time][work][end]"]').eq(0).val(limit_detail.limit_rule.time.work.end);
						}
						if(limit_detail.limit_rule.time.rest){
							if(limit_detail.limit_rule.time.rest.start==''){}else{
								timemain += `<div>
											<div>节假日 ${limit_detail.limit_rule.time.rest.start}-${limit_detail.limit_rule.time.rest.end}</div>
										</div>`;
							}
						$('#tab'+typenum).find('input[name="limit_rule[time][rest][start]"]').eq(0).val(limit_detail.limit_rule.time.rest.start);
						$('#tab'+typenum).find('input[name="limit_rule[time][rest][end]"]').eq(0).val(limit_detail.limit_rule.time.rest.end);
						}
						if(limit_detail.limit_rule.time.week){
							if(limit_detail.limit_rule.time.week[1]){
								timemain+=`<div>
									周一
									${limit_detail.limit_rule.time.week[1].start}-
									${limit_detail.limit_rule.time.week[1].end}
									</div>`
								$('#tab'+typenum).find('input[name="limit_rule[time][week][1][start]"]').eq(0).val(limit_detail.limit_rule.time.week[1].start);
								$('#tab'+typenum).find('input[name="limit_rule[time][week][1][end]"]').eq(0).val(limit_detail.limit_rule.time.week[1].end);
							}
							if(limit_detail.limit_rule.time.week[2]){
								timemain+=`<div>
									周二
									${limit_detail.limit_rule.time.week[2].start}-
									${limit_detail.limit_rule.time.week[2].end}
									</div>`
								$('#tab'+typenum).find('input[name="limit_rule[time][week][2][start]"]').eq(0).val(limit_detail.limit_rule.time.week[2].start);
								$('#tab'+typenum).find('input[name="limit_rule[time][week][2][end]"]').eq(0).val(limit_detail.limit_rule.time.week[2].end);
							}
							if(limit_detail.limit_rule.time.week[3]){
								timemain+=`<div>
									周三
									${limit_detail.limit_rule.time.week[3].start}-
									${limit_detail.limit_rule.time.week[3].end}
									</div>`
								$('#tab'+typenum).find('input[name="limit_rule[time][week][3][start]"]').eq(0).val(limit_detail.limit_rule.time.week[3].start);
								$('#tab'+typenum).find('input[name="limit_rule[time][week][3][end]"]').eq(0).val(limit_detail.limit_rule.time.week[3].end);
							}
							if(limit_detail.limit_rule.time.week[4]){
								timemain+=`<div>
									周四
									${limit_detail.limit_rule.time.week[4].start}-
									${limit_detail.limit_rule.time.week[4].end}
									</div>`
								$('#tab'+typenum).find('input[name="limit_rule[time][week][4][start]"]').eq(0).val(limit_detail.limit_rule.time.week[4].start);
								$('#tab'+typenum).find('input[name="limit_rule[time][week][4][end]"]').eq(0).val(limit_detail.limit_rule.time.week[4].end);
							}
							if(limit_detail.limit_rule.time.week[5]){
								timemain+=`<div>
									周五
									${limit_detail.limit_rule.time.week[5].start}-
									${limit_detail.limit_rule.time.week[5].end}
									</div>`
								$('#tab'+typenum).find('input[name="limit_rule[time][week][5][start]"]').eq(0).val(limit_detail.limit_rule.time.week[5].start);
								$('#tab'+typenum).find('input[name="limit_rule[time][week][5][end]"]').eq(0).val(limit_detail.limit_rule.time.week[5].end);
							}
							if(limit_detail.limit_rule.time.week[6]){
								timemain+=`<div>
									周六
									${limit_detail.limit_rule.time.week[6].start}-
									${limit_detail.limit_rule.time.week[6].end}
									</div>`
								$('#tab'+typenum).find('input[name="limit_rule[time][week][6][start]"]').eq(0).val(limit_detail.limit_rule.time.week[6].start);
								$('#tab'+typenum).find('input[name="limit_rule[time][week][6][end]"]').eq(0).val(limit_detail.limit_rule.time.week[6].end);
							}
							if(limit_detail.limit_rule.time.week[7]){
								timemain+=`<div>
									周日
									${limit_detail.limit_rule.time.week[7].start}-
									${limit_detail.limit_rule.time.week[7].end}
									</div>`
								$('#tab'+typenum).find('input[name="limit_rule[time][week][7][start]"]').eq(0).val(limit_detail.limit_rule.time.week[7].start);
								$('#tab'+typenum).find('input[name="limit_rule[time][week][7][end]"]').eq(0).val(limit_detail.limit_rule.time.week[7].end);
							}
							
							
							
						}
						console.log(timemain)
						if(timemain==""){
							timemain='不限'
						}else{}
						if(typenum==1){
								console.log(timemain)
								$('.time_type1').html(timemain);
							}else{
								$('.time_type2').html(timemain);
							}
					}
					
					}
					}
		}
		
		//添加审批员
		function addapproveshow2(clickleve, clicktype,main){
			var lload=layer.load(3, {
			shade: [0.1, '#fff'] //0.1透明度的白色背景
		});
			$.ajax({
			type: "post",
			url: "{:url('/unit/staff/all')}",
			data: {},
			success: function(res) {
				layer.close(lload)
				var approvalall=[];
				for(var i1 = 0; i1 < res.data.length; i1++) {
					if(res.data[i1].is_check==1) {
						approvalall.push(res.data[i1])
					}
				}
				console.log(approvalall)
				var addlist = '';
				var addlist2 = '';
				for(var ii1 = 0; ii1 < main.length; ii1++) {
					for(var ii2 = 0; ii2 < approvalall.length; ii2++) {
						if(main[ii1]==approvalall[ii2].passenger_id){
						var addlist_id = approvalall[ii2].passenger_id;
						var addlist_name = approvalall[ii2].name;
						var addlist_phone = approvalall[ii2].phone;
						addlist += `<li class="approver_list" data-id='${addlist_id}'>
								${addlist_name} ${addlist_phone} <i class="am-icon-close"></i>
							</li>`
						addlist2 += `<option selected value='${addlist_id}'>
		  						${addlist_name}
		  					</option>`
						}
				}
				}
				var classname = '.approval_ul' + clickleve
				var classname2 = '.approval_select' + clickleve
				if(clicktype == 1) {
					$('#tab1').find(classname).html(addlist);
					$('#tab1').find(classname2).html(addlist2);
				} else {
					$('#tab2').find(classname).html(addlist);
					$('#tab2').find(classname2).html(addlist2);
				}
				removeapprove()
			}
		})
		
	};
	{else/}
	$("#loading-first").fadeOut(500);
	$("select[name='limit_rule[type][]']").eq(0).selected({
	   btnWidth:'200px', btnSize: 'sm'
	});
	$("select[name='limit_rule[type][]']").eq(1).selected({
	   btnWidth:'200px', btnSize: 'sm'
	});
	$("select[name='limit_rule[car_type][]']").eq(0).selected({
	   btnWidth:'200px', btnSize: 'sm'
	});
	$("select[name='limit_rule[car_type][]']").eq(1).selected({
	   btnWidth:'200px', btnSize: 'sm'
	});
	{/if}
	function addapproveprople(clickleve, clicktype) {
		console.log(clicktype)
		var addload = layer.load(1, {
			shade: [0.1, '#fff'] //0.1透明度的白色背景
		});
		$.ajax({
			type: "post",
			url: "{:url('/unit/staff/all')}",
			data: {},
			success: function(res) {
				layer.close(addload)
				var approverlist = []
				for(var i1 = 0; i1 < res.data.length; i1++) {
					if(res.data[i1].is_check==1) {
						approverlist.push(res.data[i1])
					}
				}
				console.log(approverlist)
				var namelist = `<div style="padding:20px"><div><ul style='width:100%;height:150px;overflow:auto'>`

				for(var i2 = 0; i2 < approverlist.length; i2++) {
					namelist += `<li class="approver_list" data-id='${approverlist[i2].passenger_id}' data-check='0' style='margin:10px 10px 0 0'>
								<span class='approver_list_name'>${approverlist[i2].name}</span><span class='approver_list_phone'> ${approverlist[i2].phone} </span>
							</li>`
				}
				namelist += `</ul>
						</div>
						<div class='am-u-sm-12 cl-p' style='margin-top:10px'>
							<button class='am-btn am-btn-sm am-btn-primary approconfirm'>确定</button>
							<button class='am-btn am-btn-sm am-btn-default approclose'>取消</button>
						</div>
						</div>`
				var appro = layer.open({
					type: 1,
					title: false,
					id: 'approverall',
					skin: 'layui-layer-rim', //加上边框
					area: ['420px', '240px'], //宽高
					content: namelist,
					success: function() {
						$('#approverall .approver_list').on('click', function() {
							if($(this).css('background') == 'yellow') {
								$(this).data('check', '0')
								$(this).css('background', '#fff');
							} else {
								$(this).data('check', '1')
								$(this).css('background', 'yellow');

							}
						})
						$('.approconfirm').on('click', function() {
							addapproveshow(clickleve, clicktype)
							layer.close(appro)
						})
						$('.approclose').on('click', function() {
							layer.close(appro)
						})
					}
				});
			}
		})
	}
	function addapproveshow(clickleve, clicktype){
		var addlist = '';
			var addlist2 = '';
			for(var ii1 = 0; ii1 < $('#approverall .approver_list').length; ii1++) {
				if($('#approverall .approver_list').eq(ii1).data('check')) {
					var addlist_id = $('#approverall .approver_list').eq(ii1).data("id");
					var addlist_name = $('#approverall .approver_list').eq(ii1).find('.approver_list_name').html();
					var addlist_phone = $('#approverall .approver_list').eq(ii1).find('.approver_list_phone').html();
					addlist += `<li class="approver_list" data-id='${addlist_id}'>
							${addlist_name} ${addlist_phone} <i class="am-icon-close"></i>
						</li>`
					addlist2 += `<option selected value='${addlist_id}'>
	  						${addlist_name}
	  					</option>`
				}
			}
			var classname = '.approval_ul' + clickleve
			var classname2 = '.approval_select' + clickleve
			if(clicktype == 1) {
				$('#tab1').find(classname).html(addlist);
				$('#tab1').find(classname2).html(addlist2);
			} else {
				$('#tab2').find(classname).html(addlist);
				$('#tab2').find(classname2).html(addlist2);
			}
			removeapprove()
	};
	
	function removeapprove() {
		$('.approver_list .am-icon-close').unbind();
		$('.approver_list .am-icon-close').on('click', function() {
			var appop = $(this).closest('ul').parent().parent().find('select option').length
			console.log(appop)
			for(var appopidx = 0; appopidx < appop; appopidx++) {
				var opvalue = $(this).closest('ul').parent().parent().find('select option').eq(appopidx).val()
				if(opvalue == $(this).parent().data('id')) {
					$(this).closest('ul').parent().parent().find('select option').eq(appopidx).remove()
				}
			}
			$(this).parent().remove();

		})
	}
//添加审批层次
	function addapprovel(type, leve) {
		if(leve > 3) {
			Err('审批层次不能多于三层');
		} else {
			var addapprovelist1;
			var addapprove1;
			if(type == 1) {
				addapprovelist = $('.addapprovelist1').html();
				addapprove = $('.addapprove1').html();
			} else {
				addapprovelist = $('.addapprovelist2').html();
				addapprove = $('.addapprove2').html();
			}

			addapprove += `<div style="width:20px;height: 20px;background: #ccc;border-radius: 50%;"></div>
									<div style="margin: 2px 9px;background: #ccc;height: 100px;width:1px;"></div>`;
			addapprovelist += `<div style="height: 20px;font-size: 12px;line-height: 20px;font-weight: 900;">
										第${leve}级审批人
									</div>
									<div style="margin: 2px;height: 100px;">
										<div class="add_approve_people" data-type='${type}' data-leve='${leve}'>添加审批人</div>
										<div>
											<ul class='approval_ul${leve}'>
												
											</ul>
										</div>
										<select class='approval_select${leve}' name="limit_rule[checker][${leve}][]" multiple="" style="display: none;">
												
										</select>
									</div>`;
			if(type == 1) {
				approval_leve1=leve
				$('.addapprovelist1').html(addapprovelist);
				$('.addapprove1').html(addapprove);
				tab1Scroll.refresh();
			} else {
				approval_leve2=leve
				$('.addapprovelist2').html(addapprovelist);
				$('.addapprove2').html(addapprove);
				tab2Scroll.refresh();
			}
		}
	}

	$('.cartype li').on('click', function() {

		if($(this).find('div').css('display') == 'block') {
			$(this).find('div').css('display', 'none');
		} else {
			$(this).find('div').css('display', 'block');
		}
	});
//	$('.am-icon-close').on('click', function() {
//		$(this).parent().remove();
//	});
	$('.time_chang1').on('click', function() {
		opentimechang(1);
	});
	$('.time_chang2').on('click', function() {
		opentimechang(2);
	});
	$('.use_car_ra').on('click',function(){
		console.log(1)
		var radidx=$(this).closest('.use_car_date').find('input[type=radio]').length
		console.log(radidx)
		for(var ii3=0;ii3<radidx;ii3++){
			$(this).closest('.use_car_date').find('input[type=radio]').uCheck('uncheck')
		}
		$(this).uCheck('check')
		if($(this).data('astrict')){
			$(this).closest('.use_car_date').parent().find('input[name="limit_rule[date][start]"]').prop('readonly',false );
			$(this).closest('.use_car_date').parent().find('input[name="limit_rule[date][end]"]').prop('readonly', false)
		}else{
			$(this).closest('.use_car_date').parent().find('input[name="limit_rule[date][start]"]').prop('readonly', true);
			$(this).closest('.use_car_date').parent().find('input[name="limit_rule[date][end]"]').prop('readonly', true)
		}
	});
	$('.limit').on('click',function(){
		console.log(1)
		var radidx=$(this).closest('.limit-w').find('input[type=radio]').length
		console.log(radidx)
		for(var ii3=0;ii3<radidx;ii3++){
			$(this).closest('.limit-w').find('input[type=radio]').uCheck('uncheck')
		}
		$(this).uCheck('check')
		if($(this).data('astrict')){
			$(this).closest('.limit-w').find('input[name="limit_rule[quota_day]"]').prop('readonly', false);
		}else{
//			
			$(this).closest('.limit-w').find('input[name="limit_rule[quota_day]"]').prop('readonly', true)
		}
	});

	$('.keep1').on('click', function() {
		sendForm($(this));
	});
	$('.keep2').on('click', function() {
		sendForm($(this));
	});
	//用车时间
	$('.open_btn_close').on('click', function() {
		if($(this).data('type') == 1) {
			$('.time_change_main').css('display', 'none')
		} else {
			$('.time_change_main2').css('display', 'none')
		}
		$('.time_change_main').css('display', 'none')
	})
	//关闭用车时间
	$('.open_close_w').on('click', function() {
		if($(this).data('type') == 1) {
			$('.time_change_main').css('display', 'none')
		} else {
			$('.time_change_main2').css('display', 'none')
		}
	})
	//清空选项卡中的时间
	function emptytime(obj){
		for(var ttidx=0;ttidx<obj.find('input[type=time]').length;ttidx++){
			obj.find('input[type=time]').eq(ttidx).val('')
		}
	}
	//保存用车时间
	
	$('.option_keep').on('click', function() {
		var timetypemain;
		var keeptype=$(this).data('type')
		if($('#tab'+keeptype).find('.time_chang_ul').find('li[class="am-active"]').data('idx') == 1) {
			
			if($(this).data('type')==1) {
				$('.time_type1').html('不限');
				emptytime($('#tab21'));
				emptytime($('#tab31'))
			} else {
				$('.time_type2').html('不限');
				emptytime($('#tab22'));
				emptytime($('#tab32'))
			}

		} else if($('#tab'+keeptype).find('.time_chang_ul').find('li[class="am-active"]').data('idx') == 2) {
				emptytime($('#tab31'))
			if($(this).data('type')==1) {
				
				var racheck = $('.time_change_main').find('#tab21').find('input:checked').val();
				if(racheck==1){
					var racheckmain1 = $('.time_change_main').find('#tab21').find('input[type="time"]').eq(0).val();
					var racheckmain2 = $('.time_change_main').find('#tab21').find('input[type="time"]').eq(1).val();
				}else{
					var racheckmain1 = $('.time_change_main').find('#tab21').find('input[type="time"]').eq(2).val();
					var racheckmain2 = $('.time_change_main').find('#tab21').find('input[type="time"]').eq(3).val();
				}
			}else{
				var racheck = $('.time_change_main2').find('#tab22').find('input:checked').val();
				if(racheck==1){
					var racheckmain1 = $('.time_change_main2').find('#tab22').find('input[type="time"]').eq(0).val();
					var racheckmain2 = $('.time_change_main2').find('#tab22').find('input[type="time"]').eq(1).val();
				}else{
					var racheckmain1 = $('.time_change_main2').find('#tab22').find('input[type="time"]').eq(2).val();
					var racheckmain2 = $('.time_change_main2').find('#tab22').find('input[type="time"]').eq(3).val();
				}
				
			}
			console.log(racheck);
			console.log(racheckmain1);
			console.log(racheckmain2);
			if(racheck == 1) {
				timetypemain = `<div>
								<div>工作日 ${racheckmain1}-${racheckmain2}</div>
							</div>`;

			} else if(racheck == 2) {
				timetypemain = `<div>
								<div>节假日 ${racheckmain1}-${racheckmain2}</div>
							</div>`;

			}
			console.log(timetypemain)
			if($(this).data('type')==1) {
				$('.time_type1').html(timetypemain);
			} else {
				$('.time_type2').html(timetypemain);
			}
		} else {
			emptytime($('#tab21'));
			var checkboxmain = `<div>`;
			if($(this).data('type')==1) {
				for(var checkidx = 0; checkidx < $('.time_change_main #tab31').find('input[type="checkbox"]').length; checkidx++) {
					if($('.time_change_main #tab31').find('input[type="checkbox"]').eq(checkidx).prop('checked')) {
						var weekdaystart1 = $('.time_change_main #tab31').find('input[type="checkbox"]').eq(checkidx).parent().parent().next().find('input[type="time"]').eq(0).val();
						var weekdaystart2 = $('.time_change_main #tab31').find('input[type="checkbox"]').eq(checkidx).parent().parent().next().find('input[type="time"]').eq(1).val();
						checkboxmain += `<div>
									${$('.time_change_main #tab31').find('input[type="checkbox"]').eq(checkidx).val()} 
									${weekdaystart1}-
									${weekdaystart2}
									</div>`;
	
					}
				}
			}else{
				for(var checkidx = 0; checkidx < $('.time_change_main2 #tab32').find('input[type="checkbox"]').length; checkidx++) {
					console.log($('.time_change_main2 #tab32').find('input[type="checkbox"]').eq(checkidx).prop('checked'))
					if($('.time_change_main2 #tab32').find('input[type="checkbox"]').eq(checkidx).prop('checked')) {
						var weekdaystart1 = $('.time_change_main2 #tab32').find('input[type="checkbox"]').eq(checkidx).parent().parent().next().find('input[type="time"]').eq(0).val();
						var weekdaystart2 = $('.time_change_main2 #tab32').find('input[type="checkbox"]').eq(checkidx).parent().parent().next().find('input[type="time"]').eq(1).val();
						checkboxmain += `<div>
									${$('.time_change_main2 #tab32').find('input[type="checkbox"]').eq(checkidx).val()} 
									${weekdaystart1}-
									${weekdaystart2}
									</div>`;
	
					}
				}
			}
			checkboxmain += `</div>`;
			if($(this).data('type')==1) {
				$('.time_type1').html(checkboxmain);
			} else {
				$('.time_type2').html(checkboxmain);
			}
		}
		if($(this).data('type')==1) {
			$('.time_change_main').css('display','none');
		} else {
			$('.time_change_main2').css('display','none');
		}
	})
	$('.week input[type=checkbox]').on('click', function() {
		var len = $(this).closest('.week').find('input[type=time]').length
		if($(this)[0].checked) {
			for(var cbidx = 0; cbidx < len; cbidx++) {
				$(this).closest('.week').find('input[type=time]').eq(cbidx).removeAttr('disabled')
			}
		} else {

			for(var cbidx = 0; cbidx < len; cbidx++) {
				$(this).closest('.week').find('input[type=time]').eq(cbidx).val('')
				$(this).closest('.week').find('input[type=time]').eq(cbidx).attr('disabled', 1)
			}
		}
	})
	$('.workdate input[type=radio]').on('click', function() {
		var radlen = $(this).closest('.workdate').find('input[type=time]').length;
		for(var kidx = 0; kidx < $(this).closest('.workdate').find('input[type=radio]').length; kidx++) {
			
			$(this).closest('.workdate').find('input[type=radio]').eq(kidx)[0].checked=false
		}
		$(this)[0].checked=true
		for(var workidx = 0; workidx < radlen; workidx++) {
			$(this).closest('.workdate').find('input[type=time]').eq(workidx).attr('disabled', 1)
		}
		var radlen2 = $(this).closest('.work_day').find('input[type=time]').length;
		for(var workidx1 = 0; workidx1 < radlen; workidx1++) {
			$(this).closest('.work_day').find('input[type=time]').eq(workidx1).removeAttr('disabled')
		}

	})

	//打开用车日期修改
	function opentimechang(number) {
		if(number == 1) {
			$('.time_change_main').css('display', 'block')
		} else {
			$('.time_change_main2').css('display', 'block')
		}

	}

})